package org.aplombh.java.awcing.basic.dp.knapsack;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * 有 N 种物品和一个容量是 V 的背包。
 * <p>
 * 第 i 种物品最多有 si 件，每件体积是 vi，价值是 wi。
 * <p>
 * 求解将哪些物品装入背包，可使物品体积总和不超过背包容量，且价值总和最大。
 * 输出最大价值。
 * <p>
 * 输入格式
 * 第一行两个整数，N，V，用空格隔开，分别表示物品种数和背包容积。
 * <p>
 * 接下来有 N 行，每行三个整数 vi,wi,si，用空格隔开，分别表示第 i 种物品的体积、价值和数量。
 * <p>
 * 输出格式
 * 输出一个整数，表示最大价值。
 * <p>
 * 数据范围
 * 0<N,V≤100
 * 0<vi,wi,si≤100
 * 输入样例
 * 4 5
 * 1 2 3
 * 2 4 1
 * 3 4 3
 * 4 5 2
 * 输出样例：
 * 10
 */
public class MultipleKnapsackProblem_4_5 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();

        MultipleKnapsackProblem multipleKnapsackProblem = new MultipleKnapsackProblem(n, m);
//        MultipleKnapsackProblemOptimize multipleKnapsackProblem = new MultipleKnapsackProblemOptimize(n, m);
        for (int i = 1; i <= n; i++) {
            multipleKnapsackProblem.v[i] = scanner.nextInt();
            multipleKnapsackProblem.w[i] = scanner.nextInt();
            multipleKnapsackProblem.s[i] = scanner.nextInt();
        }
        System.out.println(multipleKnapsackProblem.solve());
    }
}


class MultipleKnapsackProblem {
    public static final int N = 1010;
    int n, m;
    int[] f = new int[N];
    int[] v = new int[N];
    int[] w = new int[N];
    int[] s = new int[N];
    int[][] path = new int[N][N]; // 第i个物品的第j个选取了

    public MultipleKnapsackProblem(int n, int m) {
        this.n = n;
        this.m = m;
    }

    public int solve() {
        for (int i = 1; i <= n; i++) {
            for (int j = m; j >= 0; j--) {
                for (int k = 1; k <= s[i] && k * v[i] <= j; k++) {
                    if (f[j] < f[j - k * v[i]] + k * w[i]) {
                        f[j] = f[j - k * v[i]] + k * w[i];
                        path[i][j] = 1;
                    }
                }
            }
        }
        path();
        return f[m];
    }

    public void path() {
        for (int i = n, j = m; i > 0 && j > 0; ) {
            if (path[i][j] == 1 && s[i] != 0) {
                System.out.println(i);
                j -= v[i];
                s[i]--;
            } else {
                i--;
            }
        }
    }
}

class MultipleKnapsackProblemOptimize {
    public static final int N = 1010;
    int n, m;
    int[] f = new int[N];
    int[] v = new int[N];
    int[] w = new int[N];
    int[] s = new int[N];
    ArrayList<Goods> goods = new ArrayList<>();

    public MultipleKnapsackProblemOptimize(int n, int m) {
        this.n = n;
        this.m = m;
    }

    public int solve() {
        for (int i = 1; i <= n; i++) {
            for (int k = 1; k <= s[i]; k *= 2) {
                s[i] -= k;
                goods.add(new Goods(v[i] * k, w[i] * k));
            }
            if (s[i] > 0) goods.add(new Goods(v[i] * s[i], w[i] * s[i]));
        }

        for (Goods good : goods) {
            for (int j = m; j >= good.v; j--) {
                f[j] = Math.max(f[j], f[j - good.v] + good.w);
            }
        }
        return f[m];
    }
}

class Goods {
    int v, w;

    public Goods(int v, int w) {
        this.v = v;
        this.w = w;
    }
}